﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using WindowsGame.Library.IoC;
using WindowsGame.Library.ProxyObjects;
using NUnit.Framework;

namespace WindowsGame.Tests.ProxyObjects
{
	[TestFixture]
	public class ProxyObjectManagerTests
	{
		// System under test.
		private IProxyObjectManager proxyObjectManager;

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			IoCContainer.Initialize<IProxyObjectManager, ProxyObjectManager>();
		}

		[SetUp]
		public void SetUp()
		{
			proxyObjectManager = IoCContainer.Resolve<IProxyObjectManager>();
			proxyObjectManager.Clear();
		}

		[Test]
		public void ParseOneXmlFileTest()
		{
			String text =
				@"<Assets>
					<Asset name=""PencilOneSkinOne"" type=""Spaceship"">
						<ModelComponent id=""100"" shipClass=""PencilOne"" modelName=""p1_pencil"" textureName=""pencil_p1_diff_v1"" />
						<PhysicsComponent id=""200"" modelScale=""0.02"" rotateScale=""0.02"" position=""0,0,0"" rotation=""90,0,0"" boundLeft=""-400"" boundRight=""400"" boundTop=""-250"" boundBottom=""250"" />
						<ThrustComponent id=""300"" textureName=""thrust_stripSmall"" thrustFrame=""12.0"" thrustConstant=""12"" thrustMaximum=""29"" thrustFactor=""1.0"" thrustPower=""100"" bleedVelocity=""0.3"" />
					</Asset>
				</Assets>";
			XElement root = XElement.Parse(text);
			proxyObjectManager.Parse(root, "Spaceships.xml");

			Int32 count = proxyObjectManager.ProxyObjects.Count;
			Assert.AreEqual(1, count);
		}

		[Test]
		public void ParseTwoXmlFilesTest()
		{
			String text1 =
				@"<Assets>
					<Asset name=""PencilOneSkinOne"" type=""Spaceship"">
						<ModelComponent id=""100"" shipClass=""PencilOne"" modelName=""p1_pencil"" textureName=""pencil_p1_diff_v1"" />
						<PhysicsComponent id=""200"" modelScale=""0.02"" rotateScale=""0.02"" position=""0,0,0"" rotation=""90,0,0"" boundLeft=""-400"" boundRight=""400"" boundTop=""-250"" boundBottom=""250"" />
						<ThrustComponent id=""300"" textureName=""thrust_stripSmall"" thrustFrame=""12.0"" thrustConstant=""12"" thrustMaximum=""29"" thrustFactor=""1.0"" thrustPower=""100"" bleedVelocity=""0.3"" />
					</Asset>
				</Assets>";
			XElement root1 = XElement.Parse(text1);
			proxyObjectManager.Parse(root1, "Spaceships.xml");

			String text2 =
				@"<Assets>
					<Asset name=""PeashooterOne"" type=""Weapon"">
						<ModelComponent id=""100"" modelName=""p1_pea"" textureName=""pea_proj"" />
						<PhysicsComponent id=""200"" modelScale=""0.02"" rotation=""90,0,0"" boundLeft=""-400"" boundRight=""400"" boundTop=""-250"" boundBottom=""250"" />
						<WeaponComponent id=""400"" cost=""0 "" lifetime=""3"" maximum=""5"" burst=""1"" acceleration=""0"" damage=""1"" />
					</Asset>
				</Assets>";

			XElement root2 = XElement.Parse(text2);
			proxyObjectManager.Parse(root2, "Weapons.xml");

			Int32 count = proxyObjectManager.ProxyObjects.Count;
			Assert.AreEqual(2, count);
		}

		[TestFixtureTearDown]
		public void TestFixtureTearDown()
		{
			IoCContainer.Release();
		}
	}
}